
***Note: replicators should set directory to open data 
*cd ""

*Also note data are in .sav format, need to be put in stata

********** FIGURE 2e: Ethnoracial Attitudes, US **********

*Based on Pew Research data, see appendix. Original dataset: https://www.pewsocialtrends.org/dataset/2016-racial-attitudes-in-america-survey/.  

clear all
use Pew.dta

 label var D "Discriminatory attitudes"
 label var PD "Perceptions of discrimination"

 *this is just for readability - without it, the graph looks squashed in the middle, with empty blanck spaces
 drop if D<.29
 drop if D>.98

gen Northeast=0
replace  Northeast=1 if sstate=="Connecticut" | sstate=="Maine" | sstate=="Massachusetts" | sstate=="New Hampshire" | sstate=="New Jersey" | sstate=="New York" | sstate=="Pennsylvania" | sstate=="Rhode Island" | sstate=="Vermont"  
	
gen Midwest=0
replace  Midwest=1 if sstate=="Illinois" | sstate=="Indiana" | sstate=="Iowa" | sstate=="Kansas" | sstate=="Michigan" | sstate=="Minnesota" | sstate=="Missouri" | sstate=="Nebraska" | sstate=="North Dakota" | sstate=="South Dakota" | sstate=="Ohio"  | sstate=="Wisconsin" 
	
gen South=0
replace  South=1 if sstate=="Alabama" | sstate=="Arkansas" | sstate=="District of Columbia" | sstate=="Delaware" | sstate=="Florida" | sstate=="Georgia" | sstate=="Kentucky" | sstate=="Louisiana" | sstate=="Maryland" | sstate=="Mississippi" | sstate=="North Carolina"  | sstate=="South Carolina" | sstate=="Oklahoma"  | sstate=="West Virginia" | sstate=="Virginia"   | sstate=="Texas" | sstate=="Tennessee"

gen West=0
replace  West=1 if sstate=="Alaska" | sstate=="Arizona" | sstate=="California" | sstate=="Colorado" | sstate=="Hawaii" | sstate=="Idaho" | sstate=="Montana" | sstate=="Nevada" | sstate=="Oregon" | sstate=="New Mexico" | sstate=="Utah"   | sstate=="Washington" | sstate=="Wyoming"  


gen Area=.
replace Area=1 if Midwest==1
replace Area=2 if Northeast==1
replace Area=3 if South==1
replace Area=4 if West==1
 

label variable Area "Continent"
la def aria  1 "Midwest" 2 "Northeast"  3 "South" 4 "West" , modify
la val Area aria

   grstyle init
 grstyle set legend 2,  nobox
 grstyle set size 8pt: tick_label key_label
 grstyle set size 12pt: heading
 grstyle set size 10pt: subheading axis_title 
 grstyle set graphsize 13cm 11.5cm

 
reg    PD D
ereturn list
loc N6= e(N)
local b= round(_b[D],.001)
local t = _b[D]/_se[D]
local p =round(2*ttail(e(df_r),abs(`t')),.001)


  graph twoway    (lfitci PD  D if D>.2,   lcol(black)  lwidth(medthick) ciplot(rline) blpattern(dash) acolor(black%65) )     (scatter PD  D if Area==1,       mcolor(black)   msymbol(d))   (scatter PD  D if Area==2,   mcolor(black)    msymbol(S)) (scatter PD  D if Area==3,   mcolor(black)      msymbol(o)) (scatter PD  D if Area==4,   mcolor(black)    msymbol(T)), name(a, replace)   xlabel(0.3(.1)1) xscale(range(0.3 1))  legend(position(12) rows(1)  order(3 "Midwest" 4 "Northeast"  5 "South" 6 "West") span) ytitle("Perceptions of discrimination")    xtitle("Discriminatory attitudes") note("Author's computation based on the Pew Research Center." "Plot country-round pairwise correlation. {&rho} = `b' | {it:p-value} = `p' | {it:N} = `N6'." ,size(vsmall) span) subtitle("{bf: Ethnoracial attitudes in the U.S.}") 
  graph export "Graph/Figure2e.tif", replace 
  graph save "Graph/Figure2e", replace
 
 
